package com.longrise.co;

import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.util.Log;

import com.longrise.co.ui.MainFragment;
import com.longrise.co.utils.Constants;
import com.ly.common.base.BaseActivity;

public class MainActivity extends BaseActivity {

    @Override
    public int getLayoutId() {
        return R.layout.activity_container;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        loadRootFragment(R.id.content, MainFragment.newInstance());
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == MainFragment.MY_PERMISSION_REQUEST_CODE) {
            boolean isAllGranted = true;

            // 判断是否所有的权限都已经授予了
            for (int grant : grantResults) {
                if (grant != PackageManager.PERMISSION_GRANTED) {
                    isAllGranted = false;
                    break;
                }
            }

            if (isAllGranted) {
                // 如果所有的权限都授予了, 则执行备份代码
                mRxManager.post(Constants.RX_EVENT_UPDATE, null);
            } else {
                // 弹出对话框告诉用户需要权限的原因, 并引导用户去应用权限管理中手动打开权限按钮
                showErrorTip("拒绝权限将影响App的正常使用!");
            }
        }
        Log.i("luoyang", "");
    }
}
